package point;

public class PointTest {

	public static void main(String[] args) {
		Point p1 = new Point(3, 5);
		Point p2 = new Point(4, 1);
		Point p3 = new Point(4, 1);

		// Equality
		System.out.println(p2.equals(p3));
		// Identity
		System.out.println(p2 == p3);
		// The upper variables reference different objects, however they are
		// logically equal

		// Object Hashcode
		System.out.println(p2.hashCode());

		// Hashcode is int and therefore can be compared with '=='
		System.out.println(p2.hashCode() == p3.hashCode());
		// The hashcode function MUST produce the same hashcode for logically
		// equal objects.

		System.out.println(p1.hashCode() == p2.hashCode());
		// And in the perfect case, each pair of different objects must have
		// different hashcode. However, that is rarely possible

		// Cloning objects
		Object obj = p1.clone();
		System.out.println(obj.getClass()); // Should be the same class as p1
		System.out.println(obj.equals(p1)); // Should be true
		System.out.println(obj == p1); // Should be false

		Point p4 = (Point) obj;
		// Here the Point's toString() method is automatically called
		System.out.println(p4);
		// Which method will be called? 
		// The Point's or the Object's toString() method?
		System.out.println(obj);
	}

}
